home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
StreamBuf.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-20
|
3KB
|
94 lines
#ifndef StreamBuf_First
#ifdef __GNUG__
//pragma once
#pragma interface
#endif
#define StreamBuf_First
#include "Types.h"
#ifndef BUFSIZE
#define BUFSIZE 4096
#endif
#define zapeof(c) ((c) & 0377)
class StreamBuf { // a buffer for streams
protected:
StreamBuf *sb; // base streambuf
char* base; // pointer to beginning of buffer
char* ptr; // pointer to next free byte
char* gptr; // pointer to next free byte
char* eptr; // pointer to first byte following buffer
bool alloc; // true if buffer is allocated using "new"
long fpos;
public:
StreamBuf(int size= BUFSIZE, char *p= 0, int count= 0, bool alloc= FALSE);
virtual ~StreamBuf();
void Finish();
void SetBaseStream(StreamBuf *s);
StreamBuf *GetBaseStream();
// supply an area for a buffer.
// The "count" parameter allows the buffer to start in non-empty.
StreamBuf *setbuf(char *p, int len, int count= 0, bool alloc= FALSE);
// return size of buffer
u_long size()
{ return (u_long) (eptr-base); }
// Empty a buffer. Return EOF on error; 0 on success
virtual int overflow(int c= EOF);
// Fill a buffer. Return EOF on error or end of input; next character on success
virtual int underflow();
virtual int Underflow(u_char *bp, int size);
virtual int Overflow(u_char *bp, int size);
virtual void Close();
virtual long Seek(long pos, int whence);
int seek(long pos, bool relative= FALSE);
long tell()
{ return fpos + (long) (ptr-base); }
char *Base()
{ return base; }
int sgetc() // get the current character
{ return (ptr >= gptr) ? underflow() : zapeof(*ptr); }
int sbumpc() // get the current character and advance to the next character
{ return (ptr >= gptr) ? underflow() : zapeof(*ptr++); }
int snextc() // get the next character
{ return (ptr >= (gptr-1)) ? underflow() : zapeof(*++ptr); }
inline void stossc() // advance to the next character
{ if (ptr++ >= gptr) underflow(); }
// Return a character to the buffer (ala lookahead 1). Since
// the user may be "playing games" the character might be
// different than the last one returned by sgetc or snextc.
// been extracted, nothing will be put back.
// Putting back an EOF is DANGEROUS.
void sputbackc(char c);
// put a character into the buffer
inline int sputc(int c= EOF)
{ return (eptr <= ptr) ? overflow(zapeof(c)) : (*ptr++= zapeof(c)); }
// put n characters into the buffer
int sputn(const char *buf, int n);
// get n characters from the buffer
int sgetn(char *buf, int n);
int salloc(char **buf, int size);
};
#endif